<?php
use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;

/* @var $this yii\web\View */
/* @var $content string 字符串 */


$web = Url::to("@web");

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <title>产品详情</title>
    <link type="text/css" href="<?= $web ?>/css/wx-good/global.css" rel="stylesheet"/>
    <link type="text/css" href="<?= $web ?>/css/swiper.min.css" rel="stylesheet">
    <link type="text/css" href="<?= $web ?>/css/wx-good/goods-detail.css" rel="stylesheet"/>
    <script type="text/javascript" src="<?= $web ?>/js/jquery.js"></script>
    <script type="text/javascript" src="<?= $web ?>/js/tools.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var w = $(document).width();
            if (w > 640) {
                w = 640;
            }
            $("html").css("font-size", w * 20 / 320);

        });

        function addShoppingCart(goods_code) {
            var goods_num = $('#hidden_GOODS_NUM').val();
            if (goods_num > 99) {
                alert("买的太多了");
                return;
            }

            $("#loading_toast").show();

            var data = {};
            data.goods_code = goods_code;

            requestJson('<?=Url::to(['wx-good/add-goods-to-cart-handle'])?>', data, true, function (response) {
                $("#loading_toast").hide();

                if (response.status == 0) {
                    if (response.data.TOTALNUM > 99) {
                        $('#v_TOTALNUM').html('99+');
                    } else {
                        $('#v_TOTALNUM').html(response.data.TOTALNUM);
                    }
                    $('#hidden_GOODS_NUM').val(response.data.GOODSNUM);
                    $("#confirm_dialog").show();
                } else {
                    alert(response.message);
                }
            });
        }

        function create_order(goods_code) {
            var stock = <?= $stock ?>;
            if (stock <= 0) {
                alert("库存不足。");
                return false;
            }
            window.location.href = "<?=Url::to(["wx-good/create-goods-to-order-handle"]);?>?goods_code=" + goods_code;
        }

        function create_virtual_goods_order(goods_code) {
            var stock = <?= $stock ?>;
            if (stock <= 0) {
                alert("库存不足。");
                return false;
            }
            window.location.href = "<?=Url::to(["wx-good/create-virtual-goods-to-order-handle"]);?>?goods_code=" + goods_code;
        }

        function goto_cart() {
            window.location.href = "<?=Url::to(["wx-good/shopping-cart"]);?>";
        }

        function cancle_confirm() {
            $("#confirm_dialog").hide();
        }
    </script>
</head>

<body>
<?php
if ($goods_img != null) { ?>
    <div class="swiper-container">
        <div class="swiper-wrapper">
            <?php
            foreach ($goods_img as $picture) {
                ?>
                <div class="swiper-slide"><img src="<?= $picture['GOODS_EXHI_URL'] ?>"
                                               style="width: 16rem; height: 16rem;">
                </div>
                <?php
            }
            ?>
        </div>
        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
    </div>
<?php } ?>
<script src="<?= $web ?>/js/swiper.min.js"></script>
<script>
    var swiper = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        initialSlide: 0,
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 0,

    });
</script>
<div class="main" style="width: 16rem; margin: 0 auto;">
    <div class="description">
        <div class="description-title">
            <?= $record['GOODS_NAME'] ?>
        </div>
        <div class="description-details">
            <div class="description-details-left">
                RMB：<span><?= $record['PRICE'] ?></span>
            </div>
            <div class="description-details-right">
                库存：<span><?= $stock ?></span>
            </div>
        </div>
    </div>
    <div class="text-image-details">
        <div class="text-image-gui">
            <span>规格：</span>
            <div><?= $record['GOODS_SPEC'] ?></div>
        </div>
        <div class="text-image-gui">
            <span>型号：</span>
            <div><?= $record['GOODS_TYPE'] ?></div>
        </div>
        <div class="text-image-gui">
            <span>品牌：</span>
            <div><?= $record['GOODS_PINPAI'] ?></div>
        </div>
        <div class="text-image-hr"></div>
        <?= $record['GOODS_DETAIL_HTML'] ?>
    </div>
    <div class="foot">
        <?php
        if ($record['GOODS_CLS'] == 'KJ' || $record['GOODS_CLS'] == 'HD') {
            ?>
            <div class="foot-left" style="width: 11rem;">
                需支付RMB: <span><?= $record['PRICE'] ?></span>
            </div>
            <div class="foot-right" onclick="create_virtual_goods_order('<?= $goods_code ?>');">
                立即购买
            </div>
            <?php
        } else {
            ?>
            <div class="foot-left">
                需支付RMB: <span><?= $record['PRICE'] ?></span>
            </div>
            <div class="foot-middle" onclick="addShoppingCart('<?= $goods_code ?>')">
                <img src="<?= $web ?>/img/wx-good/product-details-1.png">
                <input class="hidden_GOODS_NUM" id="hidden_GOODS_NUM" type="hidden" value="<? $GOODSNUM ?>"/>
                <div class="foot-middle-small">
                    <span id="v_TOTALNUM"><?php if ($TOTALNUM > 99) echo '99+'; else echo $TOTALNUM; ?></span>
                </div>
            </div>
            <div class="foot-right" onclick="create_order('<?= $goods_code ?>');">
                立即购买
            </div>
            <?php
        }
        ?>

    </div>
</div>
<!--BEGIN dialog confirm-->
<div id="confirm_dialog" class="weui_dialog_confirm" style="display: none;">
    <div class="weui_mask"></div>
    <div class="weui_dialog">
        <div class="weui_dialog_hd">
            <div class="weui_dialog_title">添加购物车成功，是否需要进入购物车?</div>
        </div>
        <div class="weui_dialog_bd">
        </div>
        <div class="weui_dialog_ft">
            <a href="javascript:;" class="weui_btn_dialog default" onclick="cancle_confirm();">取消</a>
            <a href="javascript:;" class="weui_btn_dialog primary" onclick="goto_cart();">确定</a>
        </div>
    </div>
</div>
<!--END dialog confirm-->

<!-- loading toast -->
<div id="loading_toast" class="weui_loading_toast" style="display:none;">
    <div class="weui_mask_transparent"></div>
    <div class="weui_toast">
        <div class="weui_loading">
            <div class="weui_loading_leaf weui_loading_leaf_0"></div>
            <div class="weui_loading_leaf weui_loading_leaf_1"></div>
            <div class="weui_loading_leaf weui_loading_leaf_2"></div>
            <div class="weui_loading_leaf weui_loading_leaf_3"></div>
            <div class="weui_loading_leaf weui_loading_leaf_4"></div>
            <div class="weui_loading_leaf weui_loading_leaf_5"></div>
            <div class="weui_loading_leaf weui_loading_leaf_6"></div>
            <div class="weui_loading_leaf weui_loading_leaf_7"></div>
            <div class="weui_loading_leaf weui_loading_leaf_8"></div>
            <div class="weui_loading_leaf weui_loading_leaf_9"></div>
            <div class="weui_loading_leaf weui_loading_leaf_10"></div>
            <div class="weui_loading_leaf weui_loading_leaf_11"></div>
        </div>
        <p class="weui_toast_content">数据加载中</p>
    </div>
</div>
<!-- end loading toast -->
</body>
</html>
